
/**
 * 财务管理控制层
 */
define([ "app", "jquery", "md5", "ecb", 
        "services/UserService",
		"resources/UserResource", 
		"directives/yoki/AddVspot",
		"resources/AddYokiViewSpotResource"], function(app) {

	var deps = [ "$scope", "$state", "$modal","$location", "$stateParams","UserService","UserResource","AddYokiViewSpotResource"];

	function controller($scope, $state, $modal,$location, $stateParams,UserService,UserResource,AddYokiViewSpotResource) {
		$scope.currentPage = 1;
        $scope.pages = [];
        $scope.pageSize = 10;
        //$scope.selected=10;
		queryData();
		
		function queryData(){
			AddYokiViewSpotResource.queryViewSpotList($scope.currentPage,$scope.pageSize).success(function(data){
				$scope.data = data.viewSpotList;
				if(data.count % $scope.pageSize == 0){
         			$scope.totalPage=Math.floor(data.count/$scope.pageSize);
        		}else{
        			$scope.totalPage=Math.floor(data.count/$scope.pageSize)+1;
        		}
            });
		}
		
		$scope.addVspot=function addVspot($choseVspot){
			$scope.data=null;
			queryData();
		};
		
		$scope.deleteViewSpot=function(viewSpotId){
			AddYokiViewSpotResource.deleteViewSpot(viewSpotId).success(function(data){
				queryData();
            });
		};
		
		$scope.gotoPage = function (currentNum) {
            $scope.currentPage = currentNum;
            queryData();
        };
        
        $scope.nextPage = function () {
        	if($scope.currentPage<$scope.totalPage){
        		$scope.currentPage++;
        		queryData();
        	}
        };

        $scope.upPage = function () {
        	if($scope.currentPage>1){
        		$scope.currentPage--;
        		queryData();
        	}	
        };
        $scope.changePageSize =function(){
          	//var showPageSize =$("#showPageSize").val();
          	$scope.currentPage =1;
          	//$scope.pageSize =showPageSize;
          	AddYokiViewSpotResource.queryViewSpotList($scope.currentPage,$scope.pageSize).success(function(data){
				$scope.data = data.viewSpotList;
				if(data.count % $scope.pageSize == 0){
         			$scope.totalPage=Math.floor(data.count/$scope.pageSize);
        		}else{
        			$scope.totalPage=Math.floor(data.count/$scope.pageSize)+1;
        		}
            });
        };
     
	}
	controller.$inject = deps;
	return app.lazy.controller("ViewSpotManagementController", controller);
});
